home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mig / dist / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-06  |  2.9 KB  |  130 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1991,1990 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie the
  24.  * rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    error.c,v $
  29.  * Revision 2.3  91/02/05  17:54:11  mrt
  30.  *     Changed to new Mach copyright
  31.  *     [91/02/01  17:53:53  mrt]
  32.  * 
  33.  * Revision 2.2  90/06/02  15:04:25  rpd
  34.  *     Created for new IPC.
  35.  *     [90/03/26  21:10:17  rpd]
  36.  * 
  37.  * 07-Apr-89  Richard Draves (rpd) at Carnegie-Mellon University
  38.  *    Extensive revamping.  Added polymorphic arguments.
  39.  *    Allow multiple variable-sized inline arguments in messages.
  40.  *
  41.  * 28-May-87  Richard Draves (rpd) at Carnegie-Mellon University
  42.  *    Created.
  43.  */
  44.  
  45. #include <stdio.h>
  46. #include <varargs.h>
  47. #include "global.h"
  48. #include "error.h"
  49.  
  50. extern int yylineno;
  51. extern char *yyinname;
  52.  
  53. static char *program;
  54. int errors = 0;
  55.  
  56. /*ARGSUSED*/
  57. /*VARARGS1*/
  58. void
  59. fatal(format, va_alist)
  60.     char *format;
  61.     va_dcl
  62. {
  63.     va_list pvar;
  64.     va_start(pvar);
  65.     fprintf(stderr, "%s: fatal: ", program);
  66.     (void) vfprintf(stderr, format, pvar);
  67.     fprintf(stderr, "\n");
  68.     va_end(pvar);
  69.     exit(1);
  70. }
  71.  
  72. /*ARGSUSED*/
  73. /*VARARGS1*/
  74. void
  75. warn(format, va_alist)
  76.     char *format;
  77.     va_dcl
  78. {
  79.     va_list pvar;
  80.     va_start(pvar);
  81.     if (!BeQuiet && (errors == 0))
  82.     {
  83.     fprintf(stderr, "\"%s\", line %d: warning: ", yyinname, yylineno-1);
  84.     (void) vfprintf(stderr, format, pvar);
  85.     fprintf(stderr, "\n");
  86.     }
  87.     va_end(pvar);
  88. }
  89.  
  90. /*ARGSUSED*/
  91. /*VARARGS1*/
  92. void
  93. error(format, va_alist)
  94.     char *format;
  95.     va_dcl
  96. {
  97.     va_list pvar;
  98.     va_start(pvar);
  99.     fprintf(stderr, "\"%s\", line %d: ", yyinname, yylineno-1);
  100.     (void) vfprintf(stderr, format, pvar);
  101.     fprintf(stderr, "\n");
  102.     va_end(pvar);
  103.     errors++;
  104. }
  105.  
  106. char *
  107. unix_error_string(errno)
  108.     int errno;
  109. {
  110.     extern int sys_nerr;
  111.     extern char *sys_errlist[];
  112.     static char buffer[256];
  113.     char *error_mess;
  114.  
  115.     if ((0 <= errno) && (errno < sys_nerr))
  116.     error_mess = sys_errlist[errno];
  117.     else
  118.     error_mess = "strange errno";
  119.  
  120.     sprintf(buffer, "%s (%d)", error_mess, errno);
  121.     return buffer;
  122. }
  123.  
  124. void
  125. set_program_name(name)
  126.     char *name;
  127. {
  128.     program = name;
  129. }
  130.